package com.ideheima.Test06;

/*
6、请定义一个描述矩形（MyRectangle）的类，
包含宽和高两个属性，提供获取矩形周长（perimeter）和面积（area）的方法。
并编写测试类进行测试。
 */
public class MyRectangle {
    public static void main(String[] args) {
        My m = new My(5, 5);
        m.setLength(10);
        m.setWidth(10);
        m.show();
    }
}

class My {
    //成员变量
    private double length;
    private double width;
    private double perimeter;
    private double area;

    //有参构造
    public My(double length, double width) {
        this.perimeter = (length + width) * 2;
        this.area = length * width;
        System.out.println("矩形周长:" + perimeter);
        System.out.println("矩形面积:" + area);
    }

    //无参构造方法
    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public void show() {
        this.perimeter = (length + width) * 2;
        this.area = length * width;
        System.out.println("矩形周长:" + perimeter);
        System.out.println("矩形面积:" + area);
    }
}

